<!--
 * @Author: 汪军 624473119@qq.com
 * @Date: 2023-10-22 13:13:43
 * @LastEditors: 汪军 624473119@qq.com
 * @LastEditTime: 2023-10-30 09:21:12
 * @FilePath: \app-formwork\src\pages\login\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template lang="pug">
view.agreement.px-32.py-32
  rich-text(:nodes="richHtml")
</template>

<script setup>
import { loginApi } from "@/api/login.js";
const richHtml = ref();

onLoad((options) => {
  uni.setNavigationBarTitle({
    title: options.type == 1 ? "用户协议" : "隐私政策"
  });
  getAgreement(options.type);
});

// 获取用户协议&&隐私政策
const getAgreement = (type) => {
  if (type == 1) {
    getAgreementInfo();
  } else {
    getprivacyInfo();
  }
};

// 用户协议
const getAgreementInfo = () => {
  loginApi.useragreement().then((res) => {
    res.data = res.data.replace(
      new RegExp('src="', "g"),
      `style="max-width:100%!important;" src="`
    );
    res.data = res.data.replace(
      new RegExp('style="', "g"),
      `style="max-width:100%!important;`
    );
    res.data = res.data.replace(/(<image[^>]*>)|(<table[^>]*>)/gi, function (match, capture) {
      var match = match.replace(
        /(style="(.*?)")|(width="(.*?)")|(height="(.*?)")/gi,
        'style="max-width: 100%; height: auto;"'
      );
      return match;
    });
    richHtml.value = res.data;
  });
};

// 隐私政策
const getprivacyInfo = () => {
  loginApi.userprivacy().then((res) => {
    res.data = res.data.replace(
      new RegExp('src="', "g"),
      `style="max-width:100%!important;" src="`
    );
    res.data = res.data.replace(
      new RegExp('style="', "g"),
      `style="max-width:100%!important;`
    );
    res.data = res.data.replace(/(<image[^>]*>)|(<table[^>]*>)/gi, function (match, capture) {
      var match = match.replace(
        /(style="(.*?)")|(width="(.*?)")|(height="(.*?)")/gi,
        'style="max-width: 100%; height: auto;"'
      );
      return match;
    });
    richHtml.value = res.data;
  });
};
</script>

<style lang="stylus" scoped></style>
